Improve the error message for missing packages.
authorMichael Sproul <micsproul@gmail.com>
Thu, 24 Jul 2014 11:16:20 +0000 (21:16 +1000)
committerMichael Sproul <micsproul@gmail.com>
Tue, 29 Jul 2014 07:31:57 +0000 (17:31 +1000)
src/cargo/core/resolver.rs
tests/test_cargo_compile.rs

index c693754cf969a2e2282820733536e993ae07d448..e5a6dfab1d10e189cc6d9514c63c67baf22ad172 100644 (file)
@@ -78,7 +78,13 @@ fn resolve_deps<'a, R: Registry>(parent: &PackageId,
         let pkgs = try!(ctx.registry.query(dep));
 
         if pkgs.is_empty() {
-            return Err(human(format!("No package named {} found", dep)));
+            return Err(human(format!("No package named `{:s}` found (required by `{:s}`).\n\
+                Location searched: {}\n\
+                Version required: {}",
+                dep.get_name(),
+                parent.get_name(),
+                dep.get_namespace(),
+                dep.get_version_req())));
         }
 
         if pkgs.len() > 1 {
index 3187761402593b6f2b4ea59e7aa560c8421daa8d..49e45b96f008d051bf78133dce89eaff59f75880 100644 (file)
@@ -485,6 +485,37 @@ test!(cargo_compile_with_nested_deps_longhand {
       execs().with_stdout("test passed\n"));
 })
 
+// Check that Cargo gives a sensible error if a dependency can't be found
+// because of a name mismatch.
+test!(cargo_compile_with_dep_name_mismatch {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+
+            name = "foo"
+            version = "0.0.1"
+            authors = ["wycats@example.com"]
+
+            [[bin]]
+
+            name = "foo"
+
+            [dependencies.notquitebar]
+
+            path = "bar"
+        "#)
+        .file("src/foo.rs", main_file(r#""i am foo""#, ["bar"]).as_slice())
+        .file("bar/Cargo.toml", basic_bin_manifest("bar").as_slice())
+        .file("bar/src/bar.rs", main_file(r#""i am bar""#, []).as_slice());
+
+    assert_that(p.cargo_process("cargo-build"),
+                execs().with_status(101).with_stderr(format!(
+r#"No package named `notquitebar` found (required by `foo`).
+Location searched: file:{proj_dir}
+Version required: *
+"#, proj_dir = p.root().display())));
+})
+
 // test!(compiling_project_with_invalid_manifest)
 
 test!(custom_build {